/**
 * @author Phuc "Noel" Vo
 */
package com.example.noelwhereismystuffs.models;



public class SignInModel implements ISignInModel{
	private static Database myData;
	private static User myUser = User.NULL_USER;
	private static final String TRUE = "true";
	private static final String FALSE = "false";
	private static final String LOCKACCOUNT = "lockAcount";
	private static final String ADMIN = "admin";
	private static final String NOACCOUNT = "noaccount";
	public SignInModel(Database data){
		myData = data;
	}
	
	@Override
	public String signIn(String email, String password) {
		myUser = myData.getUser(email);
		if (myUser == null){
			return NOACCOUNT;
		}
		String res = "";
		
		if (!myUser.isLocked() && myUser.getLoginAttempts() < 3){
			if (myUser.verify(password))
				if (myUser.isAdmin())
					res = ADMIN;
				else res = TRUE;
			else
				res = FALSE;
		}else{
			res = LOCKACCOUNT;
		}
		
		return res;
	}

	@Override
	public User getUser(String email) {
		return myData.getUser(email);
	}


}
